#include "gui.h"
#include "ui_gui.h"


GUI::GUI(QWidget *parent) : QMainWindow(parent), ui(new Ui::GUI)
{

        ui->setupUi(this);       

        core = new Core();

        glCanvas = new GLCanvas(0);

        ui->centralWidget->addWidget(glCanvas);

        textLog = new TextLog();

        ui->centralWidget->addWidget(textLog);

        createConnections();
}


GUI::~GUI()
{

        delete ui;
}


void GUI::createConnections()
{

        connect(core,       SIGNAL(updateMeshList(QVector<MyMesh*>*)),   glCanvas,  SLOT(updateMeshList(QVector<MyMesh*>*)));
}



// MENU ACTIONS TRIGGERED HANDLING
//
void GUI::on_action_Open_triggered()                        {   core->open_file();                              }
void GUI::on_actionSave_s_napshot_triggered()               {   glCanvas->saveSnapshot();                       }
void GUI::on_actionSave_silhouette_triggered()              {   glCanvas->saveSilhouette();                     }
void GUI::on_actionSave_augmented_silhouette_triggered()    {   glCanvas->saveAugmentedSilhouette();            }
void GUI::on_action_Export_to_POV_Ray_triggered()           {   glCanvas->exportToPovRay();                     }
void GUI::on_action_Points_triggered()                      {   glCanvas->setModePOINTS();                      }
void GUI::on_action_Wireframe_triggered()                   {   glCanvas->setModeWIREFRAME();                   }
void GUI::on_actionSolid_Flat_triggered()                   {   glCanvas->setModeSOLID_FLAT();                  }
void GUI::on_actionSolid_Smooth_triggered()                 {   glCanvas->setModeSOLID_SMOOTH();                }
void GUI::on_action_Hidden_Line_triggered()                 {   glCanvas->setModeHIDDEN_LINE();                 }
void GUI::on_action_Vertex_color_triggered()                {   glCanvas->setModeCOLORED_VERTICES();            }
void GUI::on_actionFace_color_flat_triggered()              {   glCanvas->setModeFLAT_COLORED_FACES();          }
void GUI::on_actionFace_color_smooth_triggered()            {   glCanvas->setModeSMOOTH_COLORED_FACES();        }
void GUI::on_action_Texture_1D_triggered()                  {   glCanvas->setModeTEXTURE_1D();                  }
void GUI::on_actionTexture_2D_triggered()                   {   glCanvas->setModeTEXTURE_2D();                  }
void GUI::on_action_Messages_triggered()                    {   ui->centralWidget->setCurrentIndex(TEXTLOG);    }
void GUI::on_action_Meshes_triggered()                      {   ui->centralWidget->setCurrentIndex(CANVAS);     }


void GUI::on_action_Mean_Curvature_triggered()
{

        core->meanCurvature();
        glCanvas->applyQualityRamp1DTexture();
}


void GUI::on_action_Gaussian_curvature_triggered()
{

        core->GaussianCurvature();
        glCanvas->applyQualityRamp1DTexture();
}


void GUI::on_actionOpen_Texture_2D_triggered()
{

        QString imgFile = QFileDialog::getOpenFileName( this, "Open 2D Texture", ".", "Images (*.png *.bmp *.jpg *.tif)");

        if (imgFile.isEmpty()) return;

        glCanvas->applyTexture(imgFile);
}
